package com.ryujung.linked_list.node;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public ListNode(int... valArr) {
        this.val = valArr[0];
        if (valArr.length > 1) {
            ListNode before = this;
            for (int i = 1; i < valArr.length; i++) {
                ListNode cur = new ListNode(valArr[i]);
                before.next = cur;
                before = cur;
            }
        }
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                ", next=" + next +
                '}';
    }
}